package util;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import model.Fengmian;
import util.FileUtil;

import java.io.File;

/**
 * Created by Administrator on 2015/6/14 0014.
 */
public class Main {
    public static final String FILE_PATH = "C:\\Users\\Administrator\\Desktop\\A3\\06社会类";
    public static final String EXCEL_PATH = "C:\\Users\\Administrator\\Desktop\\A3\\06社会类.xls";

    /**
     * 将一个文件夹里面的所有文件输出到excel中
     * @param folder
     * @param excelPath
     */
    public static void getFileToExcel(String folder,String excelPath){
        FileUtil fileUtil = new FileUtil();
        try {
            WritableWorkbook wwb = null;
            //首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
            wwb = Workbook.createWorkbook(new File(excelPath));
            if(wwb!=null){
                //创建一个可写入的工作表
                WritableSheet ws = wwb.createSheet("sheet1", 0);
                FileUtil fileUtil1 = new FileUtil();
                fileUtil.fun(new File(folder));
                if(fileUtil.fengmianList == null){
                    System.out.println("无数据");
                    return;
                }
                for(int i=0;i<fileUtil.fengmianList.size();i++){
                    Fengmian fengmian = fileUtil.fengmianList.get(i);
                    String filePath = fengmian.getPath();
                    String fileName = fengmian.getFileName();
                    Label labelC0 = new Label(0,i,fileName);
                    ws.addCell(labelC0);
                    Label labelC1 = new Label(1,i,filePath);
                    ws.addCell(labelC1);
                }
                wwb.write();
                wwb.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("ok");
    }



    public static void main(String[] args) {

    }
}
